<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <!--<script type="text/javascript" src="/templates/act/process-xl.js"></script>-->
    <style>
        .content {
            position: relative;
        }

        .btnBox {
            position: absolute;
            top: 10px;
            right: 10px;
            z-index: 1000;
        }
    </style>
</head>
<body>
<div class="content" id="view">

</div>
<script src="/static/js/main.js"></script>
<script type="text/javascript">
    layui.use(['configureCom', 'configure', 'bluebird', 'baseTab', 'sessionFun', 'jquery', 'process'], function () {
        var configure = layui.configure;
        var configureCom = layui.configureCom;
        var baseTab = layui.baseTab;
        var sessionFun = layui.sessionFun;
        var process = layui.process;
        var $ = layui.jquery;
        var listData = {};
        var decId = '';
        if (sessionFun.get(configure.SESSION_PROJECT_WAIT_LIST_DATA)) {
            listData = sessionFun.get(configure.SESSION_PROJECT_WAIT_LIST_DATA);
            decId = listData.decId;
        } else {
            listData = sessionFun.get(configure.SESSION_PROJECT_LIST_DATA);
        }
        var tabData = {
            btns: [
                {name: '保存', event: 'save'},
                {name: '保存并提交', event: 'submit'},
                {name: '关闭', event: 'close'}
            ],
            tabList: [
                {
                    title: '项目管理',
                    url: configure.PRJ_DETAIL_HTML
                }
            ]
        };
        baseTab.init(tabData, 0);
        form.on('submit', function (data) {
            var event = $(data.elem).attr('lay-event');
            switch (event) {
                case 'save':
                    save();
                    break;
                case 'submit':
                    submit();
                    break;
            }
            return false;
        });

        //保存方法
        function save() {
            //获取数据
            var ajaxUrl = '';
            configureCom.getData().then(function (res) {
                if (decId) {//如果decId存在，则为修改
                    ajaxUrl = configure.UNIT_PROJECT_APPLY_UPDATE_HTTP;
                } else {//如果decId不存在，则为新增
                    ajaxUrl = configure.UNIT_PROJECT_APPLY_HTTP;
                }
                res.result.decId = decId;
                //保存
                configureCom.postDataAjax(ajaxUrl, res.result).then(function (res) {
                    if (!decId) {
                        decId = res.decId;
                    }
                    top.layer.msg('保存成功！');
                });
            });
        }

        //保存并提交方法
        function submit() {
            //获取数据
            var ajaxUrl = '';
            //获取数据
            configureCom.getData().then(function (res) {
                if (decId) {//如果decId存在，则为修改
                    ajaxUrl = configure.UNIT_PROJECT_APPLY_UPDATE_HTTP;
                } else {//如果decId不存在，则为新增
                    ajaxUrl = configure.UNIT_PROJECT_APPLY_HTTP;
                }
                res.result.decId = decId;
                //保存
                configureCom.postDataAjax(ajaxUrl, res.result).then(function (res) {
                    if (!decId) {
                        decId = res.decId;
                    }
                    top.layer.msg('保存成功！');
                    process.startProcess({
                        "title": "测试流程 - " + listData.prjName,
                        "businessId": decId || res.decId,
                        "procDefKey": configure.XMBS
                    });
                });
            });
        }
    });


</script>
</body>
</html>